package com.angel.bo.admin.service.impl;

import com.angel.bo.admin.constants.DictCodeConstant;
import com.angel.bo.admin.service.OrganizationService;
import com.angel.bo.auth.client.jwt.AuthUtil;
import com.angel.bo.beans.admin.entity.Organization;
import com.angel.bo.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.angel.bo.admin.mapper.OrganizationMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;


/**
 * 
 *
 * @author ${author}
 * @email haibo.mei@ge.com
 * @date 2018-02-01 14:32:20
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OrganizationServiceImpl extends BaseServiceImpl<OrganizationMapper,Organization> implements OrganizationService {

    @Autowired
    private AuthUtil authUtil;


    @Override
    public void insertSelective(Organization entity) {
        entity.setCreateDate(new Date());
        entity.setCreateUserId(authUtil.getUserIdFromToken());
        entity.setState(DictCodeConstant.ORG_STATE_1);
        String showName = entity.getOrganizationName();
        if(entity.getOrganizationParentId() != null){
            Organization parentOrganization = super.selectById(entity.getOrganizationParentId());
            if(null != parentOrganization){
                showName = parentOrganization.getOrganizationName() + "-" + showName;
            }
        }
        entity.setShowOrganizationName(showName);
        super.insert(entity);
    }
}



